/**
 * @Author：ming
 * @Date：2023/9/27 1:02 AM
 * @Filename：Lc66
 */

/**
 * @author ming
 */
public class Lc66 {
    public int[] plusOne(int[] digits) {
        int res = 0;
        int temp =0;
        for (int i = digits.length-1; i >=0; i--) {
            if(i==digits.length-1){
               temp = res+digits[i]+1;
            }else {
                temp = res+digits[i];
            }

            int ge = temp%10;
            res = temp/10;
            digits[i]= ge;
        }

        int len = 0;

        if(res!=0){
            len = digits.length+1;
        }else {
            len = digits.length;
        }

        int[] a = new int[len];
        if(res!=0){
            a[0]=res;
            for (int i = 1; i < a.length; i++) {
                a[i]= digits[i-1];
            }
        }else {
            for (int i = 0; i < a.length; i++) {
                a[i] = digits[i];
            }
        }

        return a;
    }
}
